<template>
  <div>

    <!-- 阿里云视频播放器样式 -->
    <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css">
    <!-- 阿里云视频播放器脚本 -->
    <script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js"/>


    <!-- 定义播放器dom -->
    <div id="J_prismPlayer" class="prism-player"></div>
  </div>
</template>
<script>
// import vod from '@/api/vod'

import vod from "../../api/vod";
import {getAuth} from "../../api/ali";

export default {
  layout: 'video',//应用video布局
  data() {
    return{
      vid:'60e7efec1e3571efbfda5107e0c90102',
      playAuth:'',
    }
  },
  methods: {
    definedAliPlayer() {
      new Aliplayer({
        id: 'J_prismPlayer',
        vid: this.vid, // 视频id
        playauth: this.playAuth, // 播放凭证
        encryptType: '1', // 如果播放加密视频，则需设置encryptType=1，非加密视频无需设置此项
        width: '100%',
        height: '500px',
        format: 'm3u8',
        // 以下可选设置
        // cover: 'http://outin-9f8f5de7f87c11ee90d900163e16852e.oss-cn-shanghai.aliyuncs.com/8095fbb31ce671efbfeb0675b3ed0102/snapshots/22e9c911b967459d80a3f2ac5605c46d-00002.jpg?Expires=1717042746&OSSAccessKeyId=LTAI8bKSZ6dKjf44&Signature=7wRlDWjuXKlX3pP2LZQMrJ5%2FlgY%3D', // 封面
        qualitySort: 'asc', // 清晰度排序

        mediaType: 'video', // 返回音频还是视频
        autoplay: false, // 自动播放
        isLive: false, // 直播
        rePlay: false, // 循环播放
        preload: true,
        controlBarVisibility: 'hover', // 控制条的显示方式：鼠标悬停
        useH5Prism: true, // 播放器类型：html5
      }, function (player) {
        console.log('播放器创建成功')
      })
    },
    getPlayAuth(vid){
      getAuth(vid).then(
        res=>{
          this.playAuth=res.data
          console.log(this.playAuth)
          this.definedAliPlayer()
        }
      )

    }
  },
  /*asyncData({params, error}) {
    // return vod.getPlayAuth(params.vid)
    return vod.getPlayAuth('60e7efec1e3571efbfda5107e0c90102')
      .then(response => {
        return {
          playAuth: response.data,
          // vid: params.vid
          vid: '60e7efec1e3571efbfda5107e0c90102'
        }
        this.definedAliPlayer()
      })
  },*/
  mounted() { //页面渲染之后  created
    this.getPlayAuth(this.vid);
  }

}
</script>
